package com.teach.demo02;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Scanner;

public class TCPClient {

	public static void main(String[] args) {
		try {
			Socket client = new Socket("192.168.31.10", 1001);
			System.out.println("连接上了服务器");
		
			
			Scanner scanner = new Scanner(System.in);
			
			String line = null;
			
			OutputStream out = client.getOutputStream();
			DataOutputStream dout = new DataOutputStream(out);
			
			while(!"exit".equalsIgnoreCase((line = scanner.nextLine()))) {
				System.out.println("向服务器段发送消息："+line);
				dout.writeUTF(line);
				dout.flush();
			}
			

			
		
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
